package com.android.lovely.framework

import android.os.Bundle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.viewbinding.ViewBinding
import java.lang.reflect.ParameterizedType

/**
 *
 * @author why
 * @date 2025/3/7 15:13
 */
abstract class BaseMvvmActivity<DB : ViewBinding, VM : ViewModel> : BaseActivity<DB>() {
    lateinit var viewModel: VM

    override fun onCreate(savedInstanceState: Bundle?) {
        initViewModel()
        super.onCreate(savedInstanceState)
    }

    private fun initViewModel() {
        val argument = (this.javaClass.genericSuperclass as ParameterizedType).actualTypeArguments
        viewModel = ViewModelProvider(this).get(argument[1] as Class<VM>)
    }
}